// var strs = ["a"];
// var strs = ["flas", "flsaca", "fluuas"];
// var strs = ['cir','car','cat']
// var strs = ['aaa', 'aaa', 'aa']
var strs = ['c','acc','ccc'];

var logestCommonPrefix = function (strs) {
    var flag = ''
    var len = strs[0].length;
    var flagStr = [], returnStr = [];
    switch (strs.length) {
        case 0:
            return ''
        case 1:
            return strs[0];
        default:
            strs.forEach((e, index) => {
                returnStr = []
                if (len > e.length) {
                    len = e.length
                }
                for (var i = 0; i < len; i++) {
                    chars = e.charAt(i);
                    if (index == 0) {
                        flagStr[i] = chars
                    } else if (flagStr[i] != chars) {
                        len = i; 
                        return
                    } else {
                        returnStr[i] = chars
                        flagStr[i] = chars
                    }
                }
            });
            returnStr.forEach(e => {
                flag += e;
            })
            return flag
    }
}

console.log(logestCommonPrefix(strs))